package com.gwm.user.controller;


import com.gwm.common.threadlocals.UserHolder;
import com.gwm.user.dto.UserAddressDTO;
import com.gwm.user.service.TbUserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserAddressController {

    @Autowired
    private TbUserAddressService userAddressService;

//    GET /address?userId=123&id=123
    @GetMapping("/address")
    public ResponseEntity<UserAddressDTO> findById(@RequestParam("userId") Long userId, @RequestParam("id") Long id){
        UserAddressDTO userAddressDTO = userAddressService.findByUserIdAndId(userId,id);
        return ResponseEntity.ok(userAddressDTO);
    }



    @GetMapping("/address/list")
    public ResponseEntity<List<UserAddressDTO>> findByUserId(){
        String userId = UserHolder.getUserId();
        List<UserAddressDTO> userAddressDTOs = userAddressService.findByUserId(userId);
        return ResponseEntity.ok(userAddressDTOs);
    }
}
